/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aptech.eproject.controler;

import aptech.eproject.DBConnection;
import java.sql.Connection;
import aptech.eproject.entity.BillDetails;
import java.sql.*;

/**
 *
 * @author Ntienbo
 */
public class BillDetailsControler {

    DBConnection db;
    Connection conn;

    public BillDetailsControler() {
        db = new DBConnection();
    }

    public boolean insertBillDetails(BillDetails b) {
        try {
            conn = db.getConnect();
            PreparedStatement statement = conn.prepareStatement("INSERT INTO BillDetails VALUES (?,?,?,?)", ResultSet.CONCUR_UPDATABLE, ResultSet.TYPE_SCROLL_SENSITIVE);
            statement.setInt(1, b.getBillDetailID());
            statement.setInt(2, b.getBillID());
            statement.setInt(3, b.getItemID());
            statement.setInt(4, b.getItemQuantiy());

            statement.executeUpdate();
            return true;
        } catch (Exception ex) {
            return false;
        }
    }

    public boolean deleteBillDetails(BillDetails b) {
        try {
            PreparedStatement statement = conn.prepareStatement("DELETE BillDetails WHERE BillDetailID=?", ResultSet.CONCUR_UPDATABLE, ResultSet.TYPE_SCROLL_SENSITIVE);
            statement.setInt(1, b.getBillDetailID());
            statement.executeUpdate();
            return true;
        } catch (SQLException ex) {
            return false;
        }

    }

    public boolean updateBillDetails(BillDetails b) {
        try {
            PreparedStatement statement = conn.prepareStatement("UPDATE BillDetails SET"
                    + " BillID =?, ItemID =?,ItemQuantiy=? WHERE BillDetailID=?");
            statement.setInt(1, b.getBillDetailID());
            statement.setInt(2, b.getBillID());
            statement.setInt(3, b.getItemID());
            statement.setInt(4, b.getItemID());
            statement.setInt(4, b.getItemQuantiy());
            statement.setInt(5, b.getBillDetailID());
            statement.executeUpdate();
            return true;
        } catch (SQLException ex) {
            return false;
        }

    }

}
